﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SimpleSpreadsheet.Core;
using SimpleSpreadsheet.Core.Parser;
using Antlr.Runtime.Tree;
using Antlr.Runtime;

namespace SimpleSpreadsheet.Test
{
    [TestClass]
    public class ParserTest
    {
        [TestMethod]
        public void SimpleArithmeticExpression()
        {
            ExpressionLexer lexer = new ExpressionLexer(new ANTLRStringStream("10+2.0*(3-7)"));
            ExpressionParser parser = new ExpressionParser(new CommonTokenStream(lexer));

            parser.Expression();
            Assert.IsFalse(parser.HasError);
        }

        [TestMethod]
        public void BadArithmeticExpression()
        {
            ExpressionLexer lexer = new ExpressionLexer(new ANTLRStringStream("10+2*(3+7"));
            ExpressionParser parser = new ExpressionParser(new CommonTokenStream(lexer));

            try
            {
                parser.Expression();
                Assert.Fail();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Parser exception: " + e.Message);
            }
        }
    }
}
